# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import json

class SpiderTestPipeline(object):
    def __init__(self):
        self.filename = open('article.json','w')

    def process_item(self, item, spider):
        json_text = json.dumps(dict(item),ensure_ascii=False)+'\n' #dumps() 不是dump()
        self.filename.write(json_text.encode("utf-8")) #无法写入文件
        return item

    def close_spider(self,spider):
        self.filename.close()
